/**
 * 根据配置项判断数据是否需要审核
 * sys_config_item
 * LAW_REC_NEW_LITIGANT_AUDIT_FLAG
 * 0 不需要审核 1 需要审核
 */
function main() {
    let self = this;
    let tabEle = self.$$("tabs_2f5kv4");

    if (!tabEle) return;

    let tabConfig = {
        1: "form_part_8vezvv", // 法人和其他组织
        2: "form_part_bblojh", // 个体工商户
        3: "form_part_f4cph8"  // 公民
    };

    const fieldConfig = {
        1: { // 法人和其他组织
            deleteField: "number_input_e40q2m",
            enableField: "text_input_5y71lv"
        },
        2: { // 个体工商户
            deleteField: "number_input_acdpxh",
            enableField: "builtin_field_640klw"
        },
        3: { // 公民
            deleteField: "number_input_9xutej",
            enableField: "text_input_5bl4g"
        }
    };


    const currentTab = tabEle.params.currentTab;
    const currentConfig = fieldConfig[currentTab];
    const litigantFormElement = tabConfig[currentTab];

    if (!litigantFormElement) return;
    let formPartEle = self.$$(litigantFormElement);

    getSysConfigItem().then(res => {
        if (res.result) {
            if (res.data.VALID_FLAG === '1') {
                self.$$(currentConfig.deleteField).cValue = -1;
                self.$$(currentConfig.enableField).cValue = 0;
            } else {
                self.$$(currentConfig.deleteField).cValue = 0;
                self.$$(currentConfig.enableField).cValue = 1;
            }
            if (formPartEle) {
                formPartEle.$$getRenderElement().onSave().then(function(res) {
                    if (res && res.result) {
                        // 获取页面渲染元素进行跳转
                        let pageRenderElement = self.$$root().$parent.$parent.$parent;
                        if (pageRenderElement && pageRenderElement.goHistory) {
                            pageRenderElement.goHistory(-1);
                        }
                    }
                }).catch(function(error) {
                    console.error('保存失败:', error);
                });
            }
        }
    })
}


function getSysConfigItem() {
    return new Promise((resolve, reject) => {
        api.EXEC_FORMULA("ENTITY_SELECT_ONE('ds_tbl:t_d55309c8491443ceb96c1a4ccbd91bf2',VALID_FLAG,QUERY_EQ(id,'LAW_REC_NEW_LITIGANT_AUDIT_FLAG'))").then(res => {
            resolve(res);
        });
    })
}


